﻿$(function(){//延迟加载
	var dvmodelId='';
	var dvbelong='';
	
	$('#dvscript').datagrid({
		width:'auto',
		height:'auto',
		toolbar:'#tb2',
		url:'showdvscript',
		queryParams:{
			dvmodelId:dvmodelId
		},
		method:'get',
		pagination:true,
		rownumbers:true,
		fit:true,
		columns:
			[[
			{"field":"scriptname",
			"title":"脚本名称",
			"width":"10%"
			},
			{
			"field":"scripttype",
			"title":"类型",
			"width":"5%"
			},
			{
			"field":"dvfirm",
			"title":"设备厂商",
			"width":"5%"
			},
			{
			"field":"modelname",
			"title":"设备型号",
			"width":"10%"
			},
			{
			"field":"scriptpath",
			"title":"文件路径",
			"width":"7%"
			},
			{
			"field":"scriptdes",
			"title":"说明",
			"width":"40%"
			},
			{
			"field":"creatdate",
			"title":"上传日期",
			"width":"10%",
			formatter:function(value,row,index){
        		if(value!=null){
        			var date = new Date(value);
        			Y = date.getFullYear() + '-';
        			M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        			D = (date.getDate()+1 < 10 ? '0'+(date.getDate()+1) : date.getDate()+1) + ' ';
        			h =(date.getHours()+1 < 10 ? '0'+(date.getHours()+1) : date.getHours()+1) + ':';
        			m =(date.getMinutes()+1 < 10 ? '0'+(date.getMinutes()+1) : date.getMinutes()+1) + ':';
        			s =(date.getSeconds()+1 < 10 ? '0'+(date.getSeconds()+1) : date.getSeconds()+1); 
        			return Y+M+D+h+m+s;
        		}else{
        			return '';
        		}
			}},
			{
			"field":"username",
			"title":"上传人",
			"width":"10%"
			}
			]],
			onClickRow:function(index,row){
				
			},
			onLoadSuccess:function(data){
				
			}
	});
	
	var pager = $('#dvscript').datagrid('getPager');	// get the pager of datagrid
	pager.pagination({
		buttons:[{
			iconCls:'icon-add',
			handler:function(){
				
			}
		},{
			iconCls:'icon-edit',
			handler:function(){
				alert('edit');
			}
		}]
	});
	$('#dvbelong').combobox({
		onChange:function(newValue,oldValue){
			dvbelong=newValue;
		}
	});	
	$('#dvfirm').combobox({
		onChange:function(newValue,oldValue){
			if(dvbelong!=''&&newValue!=''){	
				$('#dvmodel').combobox({
					valueField:'dvmodelId',
					textField:'modelname',
					url:'getdvmodelbyfirmIdanddvbelong?dvfirmId='+newValue+'&dvbelong='+dvbelong
				});
			}
		}
	});
	
	$('#dvmodel').combobox({
		onChange:function(newValue,oldValue){
			$('#dvscript').datagrid('reload',{
				dvmodelId:newValue
			});
		}
	});
});